import http from './request.js'

const isMock = false;

export const login = (data) => {
    return http.post(`/api/auth/login`, {
        username: data.username,
        password: data.password
    })
}
export const logout = (data) => {
    return http.post(`/api/auth/logout`,{},{
        headers: {
            'Authorization': `Bearer ${localStorage.getItem('token')}`,
        }
    })
}

export const search = (data) => {
    const params = {
        keyword: data.keyword || undefined,
        category: data.category || undefined,
        securityLevel: data.securityLevel || undefined,
        page: data.page || 0,
        size: data.size || 10,
    }
    if (isMock) {
        return {
            "records": [
                {
                    "id": 1,
                    "name": "档案一",
                    "archiveNumber": "ARCH2023001",
                    "category": "财务档案",
                    "securityLevel": "内部",
                    "fileType": "PDF",
                    "fileSize": "2.5MB",
                    "filePath": "files/2023/01/营业执照.pdf",
                    "description": "2023年度企业营业执照副本",
                    "uploadUserId": 1,
                    "createTime": "2025-06-24T15:53:35",
                    "updateTime": "2025-06-24T15:53:35",
                    "deleted": 0,
                    "uploadUserName": null
                },
                {
                    "id": 2,
                    "name": "档案二",
                    "archiveNumber": "ARCH2023002",
                    "category": "人事档案",
                    "securityLevel": "内部",
                    "fileType": "DOCX",
                    "fileSize": "1.8MB",
                    "filePath": "files/2023/02/员工手册.docx",
                    "description": "公司最新版员工手册",
                    "uploadUserId": 2,
                    "createTime": "2025-06-24T15:53:35",
                    "updateTime": "2025-06-24T15:53:35",
                    "deleted": 0,
                    "uploadUserName": null
                },
                {
                    "id": 3,
                    "name": "档案三",
                    "archiveNumber": "ARCH2023003",
                    "category": "项目档案",
                    "securityLevel": "公开",
                    "fileType": "XLSX",
                    "fileSize": "3.2MB",
                    "filePath": "files/2023/03/财务报表Q1.xlsx",
                    "description": "第一季度财务报表",
                    "uploadUserId": 3,
                    "createTime": "2025-06-24T15:53:35",
                    "updateTime": "2025-06-24T15:53:35",
                    "deleted": 0,
                    "uploadUserName": null
                },
                {
                    "id": 4,
                    "name": "档案四",
                    "archiveNumber": "ARCH2023004",
                    "category": "合同档案",
                    "securityLevel": "内部",
                    "fileType": "PDF",
                    "fileSize": "4.7MB",
                    "filePath": "files/2023/04/项目A需求.pdf",
                    "description": "项目A的详细需求说明书",
                    "uploadUserId": 1,
                    "createTime": "2025-06-24T15:53:35",
                    "updateTime": "2025-06-24T15:53:35",
                    "deleted": 0,
                    "uploadUserName": null
                },
                {
                    "id": 5,
                    "name": "档案五",
                    "archiveNumber": "ARCH2023005",
                    "category": "财务档案",
                    "securityLevel": "内部",
                    "fileType": "DWG",
                    "fileSize": "8.9MB",
                    "filePath": "files/2023/05/产品B设计图纸.dwg",
                    "description": "产品B的机械设计图纸",
                    "uploadUserId": 4,
                    "createTime": "2025-06-24T15:53:35",
                    "updateTime": "2025-06-24T15:53:35",
                    "deleted": 0,
                    "uploadUserName": null
                },
                {
                    "id": 6,
                    "name": "档案六",
                    "archiveNumber": "ARCH2023006",
                    "category": "项目档案",
                    "securityLevel": "公开",
                    "fileType": "PPTX",
                    "fileSize": "5.3MB",
                    "filePath": "files/2023/06/市场调研报告.pptx",
                    "description": "2023年第二季度市场调研报告",
                    "uploadUserId": 5,
                    "createTime": "2025-06-24T15:53:35",
                    "updateTime": "2025-06-24T15:53:35",
                    "deleted": 0,
                    "uploadUserName": null
                },
                {
                    "id": 7,
                    "name": "档案七",
                    "archiveNumber": "ARCH2023007",
                    "category": "财务档案",
                    "securityLevel": "内部",
                    "fileType": "DOCX",
                    "fileSize": "0.9MB",
                    "filePath": "files/2023/07/劳动合同模板.docx",
                    "description": "公司标准劳动合同模板",
                    "uploadUserId": 2,
                    "createTime": "2025-06-24T15:53:35",
                    "updateTime": "2025-06-24T15:53:35",
                    "deleted": 0,
                    "uploadUserName": null
                },
                {
                    "id": 8,
                    "name": "档案八",
                    "archiveNumber": "ARCH2023008",
                    "category": "项目档案",
                    "securityLevel": "公开",
                    "fileType": "TXT",
                    "fileSize": "0.2MB",
                    "filePath": "files/2023/08/服务器配置.txt",
                    "description": "生产环境服务器配置说明",
                    "uploadUserId": 3,
                    "createTime": "2025-06-24T15:53:35",
                    "updateTime": "2025-06-24T15:53:35",
                    "deleted": 0,
                    "uploadUserName": null
                },
                {
                    "id": 9,
                    "name": "档案九",
                    "archiveNumber": "ARCH2023009",
                    "category": "人事档案",
                    "securityLevel": "内部",
                    "fileType": "XLSX",
                    "fileSize": "2.1MB",
                    "filePath": "files/2023/09/销售数据分析.xlsx",
                    "description": "上半年销售数据统计与分析",
                    "uploadUserId": 4,
                    "createTime": "2025-06-24T15:53:35",
                    "updateTime": "2025-06-24T15:53:35",
                    "deleted": 0,
                    "uploadUserName": null
                },
                {
                    "id": 10,
                    "name": "档案十",
                    "archiveNumber": "ARCH2023010",
                    "category": "人事档案",
                    "securityLevel": "公开",
                    "fileType": "PDF",
                    "fileSize": "3.7MB",
                    "filePath": "files/2023/10/新员工培训.pdf",
                    "description": "新员工入职培训资料合集",
                    "uploadUserId": 5,
                    "createTime": "2025-06-24T15:53:35",
                    "updateTime": "2025-06-24T15:53:35",
                    "deleted": 0,
                    "uploadUserName": null
                },
                {
                    "id": 11,
                    "name": "用户执行sql",
                    "archiveNumber": "a96305ee-25b1-4fcb-bb47-7b3e35644be1",
                    "category": "项目档案",
                    "securityLevel": "公开",
                    "fileType": "SQL",
                    "fileSize": "6.14 KB",
                    "filePath": "./uploads/66275d49-a88e-4f48-b6dd-81558c72ab30.sql",
                    "description": "test......",
                    "uploadUserId": null,
                    "createTime": null,
                    "updateTime": null,
                    "deleted": 0,
                    "uploadUserName": null
                }
            ],
            "total": 0,
            "size": 10,
            "current": 1,
            "orders": [],
            "optimizeCountSql": true,
            "searchCount": true,
            "countId": null,
            "maxLimit": null,
            "pages": 0
        }
    } else {
        return http.get(`/api/archives/search`, {
            params, headers: {
                'Authorization': `Bearer ${localStorage.getItem('token')}`,
            }
        })
    }
}
export const upload = (data) => {
    if (isMock) {
        return true
    } else {
        return http.post(`/api/archives/upload`, data,{
            headers:{
                'Authorization': `Bearer ${localStorage.getItem('token')}`,
                'Content-Type': 'multipart/form-data'
            }
        })
    }
}
export const hdfsUpload = (data) => {
    if (isMock) {
        return true
    } else {
        return http.post(`/api/hdfs/upload`, data,{
            headers:{
                'Authorization': `Bearer ${localStorage.getItem('token')}`,
                'Content-Type': 'multipart/form-data'
            }
        })
    }
}
export const hdfsView = (fileName) => {
    if (isMock) {
        return {
            "count": "10000",
            "operator": "upload",
            "content": "[\"11111\",\"11112\",\"11113\",\"11114\",\"11115\",\"11116\",\"11117\",\"11118\",\"11119\",\"111110\"]",
            "status": "success"
        }
    } else {
        return http.get(`/api/hdfs/view?fileName=${fileName}`,{
            headers:{
                'Authorization': `Bearer ${localStorage.getItem('token')}`,
                'Content-Type': 'multipart/form-data'
            }
        })
    }
}
export const hdfsDownload = (fileName) => {
    if (isMock) {
        return true
    } else {
        return http.get(`/api/hdfs/download`, {
            params: { fileName }, // 使用params对象传递参数
            headers: {
                'Authorization': `Bearer ${localStorage.getItem('token')}`,
            },
            });
    }
}
export const uploadText = (data) => {
    const params = {
        name:data.name,
        category:data.category,
        securityLevel:data.securityLevel
    }
    if (isMock) {
        return true
    } else {
        return http.post(`/api/archives/upload`, params,{
            headers:{
                'Authorization': `Bearer ${localStorage.getItem('token')}`,
            }
        })
    }
}
export const recent = (data) => {
    const params = {
        page:data.page||0,
        size:data.size||10,
    }
    if (isMock) {
        return {
            "records": [
                {
                    "id": 1,
                    "name": "档案一",
                    "archiveNumber": "ARCH2023001",
                    "category": "财务档案",
                    "securityLevel": "内部",
                    "fileType": "PDF",
                    "fileSize": "2.5MB",
                    "filePath": "files/2023/01/营业执照.pdf",
                    "description": "2023年度企业营业执照副本",
                    "uploadUserId": 1,
                    "createTime": "2025-06-24T15:53:35",
                    "updateTime": "2025-06-24T15:53:35",
                    "deleted": 0,
                    "uploadUserName": null
                },
                {
                    "id": 2,
                    "name": "档案二",
                    "archiveNumber": "ARCH2023002",
                    "category": "人事档案",
                    "securityLevel": "内部",
                    "fileType": "DOCX",
                    "fileSize": "1.8MB",
                    "filePath": "files/2023/02/员工手册.docx",
                    "description": "公司最新版员工手册",
                    "uploadUserId": 2,
                    "createTime": "2025-06-24T15:53:35",
                    "updateTime": "2025-06-24T15:53:35",
                    "deleted": 0,
                    "uploadUserName": null
                },
                {
                    "id": 3,
                    "name": "档案三",
                    "archiveNumber": "ARCH2023003",
                    "category": "项目档案",
                    "securityLevel": "公开",
                    "fileType": "XLSX",
                    "fileSize": "3.2MB",
                    "filePath": "files/2023/03/财务报表Q1.xlsx",
                    "description": "第一季度财务报表",
                    "uploadUserId": 3,
                    "createTime": "2025-06-24T15:53:35",
                    "updateTime": "2025-06-24T15:53:35",
                    "deleted": 0,
                    "uploadUserName": null
                },
                {
                    "id": 4,
                    "name": "档案四",
                    "archiveNumber": "ARCH2023004",
                    "category": "合同档案",
                    "securityLevel": "内部",
                    "fileType": "PDF",
                    "fileSize": "4.7MB",
                    "filePath": "files/2023/04/项目A需求.pdf",
                    "description": "项目A的详细需求说明书",
                    "uploadUserId": 1,
                    "createTime": "2025-06-24T15:53:35",
                    "updateTime": "2025-06-24T15:53:35",
                    "deleted": 0,
                    "uploadUserName": null
                },
                {
                    "id": 5,
                    "name": "档案五",
                    "archiveNumber": "ARCH2023005",
                    "category": "财务档案",
                    "securityLevel": "内部",
                    "fileType": "DWG",
                    "fileSize": "8.9MB",
                    "filePath": "files/2023/05/产品B设计图纸.dwg",
                    "description": "产品B的机械设计图纸",
                    "uploadUserId": 4,
                    "createTime": "2025-06-24T15:53:35",
                    "updateTime": "2025-06-24T15:53:35",
                    "deleted": 0,
                    "uploadUserName": null
                },
                {
                    "id": 6,
                    "name": "档案六",
                    "archiveNumber": "ARCH2023006",
                    "category": "项目档案",
                    "securityLevel": "公开",
                    "fileType": "PPTX",
                    "fileSize": "5.3MB",
                    "filePath": "files/2023/06/市场调研报告.pptx",
                    "description": "2023年第二季度市场调研报告",
                    "uploadUserId": 5,
                    "createTime": "2025-06-24T15:53:35",
                    "updateTime": "2025-06-24T15:53:35",
                    "deleted": 0,
                    "uploadUserName": null
                },
                {
                    "id": 7,
                    "name": "档案七",
                    "archiveNumber": "ARCH2023007",
                    "category": "财务档案",
                    "securityLevel": "内部",
                    "fileType": "DOCX",
                    "fileSize": "0.9MB",
                    "filePath": "files/2023/07/劳动合同模板.docx",
                    "description": "公司标准劳动合同模板",
                    "uploadUserId": 2,
                    "createTime": "2025-06-24T15:53:35",
                    "updateTime": "2025-06-24T15:53:35",
                    "deleted": 0,
                    "uploadUserName": null
                },
                {
                    "id": 8,
                    "name": "档案八",
                    "archiveNumber": "ARCH2023008",
                    "category": "项目档案",
                    "securityLevel": "公开",
                    "fileType": "TXT",
                    "fileSize": "0.2MB",
                    "filePath": "files/2023/08/服务器配置.txt",
                    "description": "生产环境服务器配置说明",
                    "uploadUserId": 3,
                    "createTime": "2025-06-24T15:53:35",
                    "updateTime": "2025-06-24T15:53:35",
                    "deleted": 0,
                    "uploadUserName": null
                },
                {
                    "id": 9,
                    "name": "档案九",
                    "archiveNumber": "ARCH2023009",
                    "category": "人事档案",
                    "securityLevel": "内部",
                    "fileType": "XLSX",
                    "fileSize": "2.1MB",
                    "filePath": "files/2023/09/销售数据分析.xlsx",
                    "description": "上半年销售数据统计与分析",
                    "uploadUserId": 4,
                    "createTime": "2025-06-24T15:53:35",
                    "updateTime": "2025-06-24T15:53:35",
                    "deleted": 0,
                    "uploadUserName": null
                },
                {
                    "id": 10,
                    "name": "档案十",
                    "archiveNumber": "ARCH2023010",
                    "category": "人事档案",
                    "securityLevel": "公开",
                    "fileType": "PDF",
                    "fileSize": "3.7MB",
                    "filePath": "files/2023/10/新员工培训.pdf",
                    "description": "新员工入职培训资料合集",
                    "uploadUserId": 5,
                    "createTime": "2025-06-24T15:53:35",
                    "updateTime": "2025-06-24T15:53:35",
                    "deleted": 0,
                    "uploadUserName": null
                }
            ],
            "total": 0,
            "size": 10,
            "current": 1,
            "orders": [],
            "optimizeCountSql": true,
            "searchCount": true,
            "countId": null,
            "maxLimit": null,
            "pages": 0
        }
    } else {
        return http.get(`/api/archives/recent`, {
            params,
            headers:{
                'Authorization': `Bearer ${localStorage.getItem('token')}`,
            }
        })
    }
}
export const editRecent = (data) => {
    if (isMock) {
        return true
    } else {
        return http.put(`/api/archives/${data.id}`, {
            data
        },{
            headers:{
                'Authorization': `Bearer ${localStorage.getItem('token')}`,
            }
        })
    }
}
export const deleteRecent = (id) => {
    if (isMock) {
        return true
    } else {
        return http.delete(`/api/archives/${id}`,{
            headers:{
                'Authorization': `Bearer ${localStorage.getItem('token')}`,
            }
        })
    }
}
// 馆藏统计
export const securityLevel = () => {
    if (isMock) {
        return {
            "公开": 15,
            "内部": 30
        }
    } else {
        return http.get(`/api/archives/security-level`,{
            headers:{
                'Authorization': `Bearer ${localStorage.getItem('token')}`,
            }
        })
    }
}

// 馆藏统计
export const todayVisits = () => {
    if (isMock) {
        return 156
    } else {
        return http.get(`/api/stats/today-visits`,{
            headers:{
                'Authorization': `Bearer ${localStorage.getItem('token')}`,
            }
        })
    }
}

// 馆藏统计
export const monthViews = () => {
    if (isMock) {
        return 2456
    } else {
        return http.get(`/api/stats/month-views`,{
            headers:{
                'Authorization': `Bearer ${localStorage.getItem('token')}`,
            }
        })
    }
}

// 馆藏统计
export const downloads = () => {
    if (isMock) {
        return 873
    } else {
        return http.get(`/api/stats/downloads`,{
            headers:{
                'Authorization': `Bearer ${localStorage.getItem('token')}`,
            }
        })
    }
}

// 馆藏统计
export const recentLimit = (limit) => {
    if (isMock) {
        return [
            "admin 在 2025-06-27 18:21:36 时执行了 上传 操作",
            "admin 在 2025-06-27 18:15:31 时执行了 登陆 操作",
            "admin 在 2025-06-27 17:56:46 时执行了 登陆 操作",
            "admin 在 2025-06-26 15:29:23 时执行了 登陆 操作",
            "admin 在 2025-06-26 15:24:20 时执行了 登陆 操作"
        ]
    } else {
        return http.get(`/api/auth/recent/${limit}`,{
            headers:{
                'Authorization': `Bearer ${localStorage.getItem('token')}`,
            }
        })
    }
}

// 按照类别统计
export const getCategoryData = (category) => {
    return http.get(`/api/archives/category/${category}`,{
        headers:{
            'Authorization': `Bearer ${localStorage.getItem('token')}`,
        }
    })
}

export const viewContent = (id)=>{
    if (isMock) {
        return '123'
    }else{
        return http.get(`/api/archives/vew/${id}`,{
            headers:{
                'Authorization': `Bearer ${localStorage.getItem('token')}`,
            }
        })
    }
}

